package com.jydd.mybroadcastreceiverstudy;

import android.content.IntentFilter;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

public class MainActivity extends AppCompatActivity {
    private MyReceiver mMyReceiver;
    private IntentFilter intentFilter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Util.log("onCreate");
        setContentView(R.layout.activity_main);
        if(savedInstanceState == null){
            getSupportFragmentManager().beginTransaction().add(R.id.container, new MainFragment()).commit();
        }
        mMyReceiver = new MyReceiver();
        intentFilter = new IntentFilter();
        intentFilter.addAction(Util.DYNAMIC_RECEIVER_ACTION);

    }

    @Override
    protected void onResume() {
        super.onResume();
        Util.log("onResume");
        LocalBroadcastManager.getInstance(this).registerReceiver(mMyReceiver,intentFilter);
    }

    @Override
    protected void onPause() {
        super.onPause();
        Util.log("onPause");
        LocalBroadcastManager.getInstance(this).unregisterReceiver(mMyReceiver);
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onStart() {
        super.onStart();
        Util.log("onStart");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Util.log("onDestroy");
    }
}
